<?php
declare (strict_types=1);

namespace app\api\controller;

use app\common\tool\Result;
use think\Response;
use app\common\model\News as NewsModel;

class News extends Base
{
    public function index(): Response
    {
        return Result::fastReturn(NewsModel::getPageList([], 'id,title,describe,images,create_time',
            $this->getPage(), $this->getLimit(), true, [], []));
    }

    public function info($id): Response
    {
        $info = NewsModel::where(['id' => $id, 'status' => 1])
            ->field('id,title,describe,images,content,create_time')->find();
        if (!$info) {
            return Result::fail('公告不存在');
        }
        $info->content = handleRichText($info->content);

        return Result::success('success', $info);
    }
}